package yxy.game.pm2.bean.db.dao;

import java.util.Collection;
import java.util.List;

import yxy.apple.database.BaseDAO;
import yxy.apple.database.DAOManager;
import yxy.game.pm2.bean.db.module.whitelist;

public class MySQLWhiteListDAO extends BaseDAO<whitelist> {

	public static Collection<whitelist> get(int accountId) {
		try {
			String sql = String.format("from whitelist as ts where ts.accountId = %d", accountId);
			List<whitelist> list = query(DAOManager.getGameH(), sql, null);
			return list;
		} catch (Exception e) {
			return null;
		}
	}

	public static whitelist getByServerId(int accountId, int serverId) {
		try {
			String sql = String.format("from whitelist as ts where ts.accountId = %d and server_id = %d", accountId, serverId);
			return queryOne(DAOManager.getGameH(), sql, null);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static int countByServerId(int accountId, int serverId) {
		try {
			String sql = String.format("from whitelist as ts where ts.accountId = %d and server_id = %d", accountId, serverId);
			return getCount(DAOManager.getGameH(), sql, null);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

}
